package com.libraryManage.controller;

import com.libraryManage.commons.utils.ResponseEntity;
import com.libraryManage.service.UserManageService;
import com.libraryManage.vo.BookManageVo;
import com.libraryManage.vo.BorrowVo;
import com.libraryManage.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @CreateDate 2021-02-08
 * @Author yufang
 */
@Api(tags={"用户管理接口"})
@RestController
@CrossOrigin
@RequestMapping("manage/user")
public class UserManageController {

    @Autowired
    UserManageService userManageService;

    @ApiOperation("获取所有用户")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/getUserList" , method = RequestMethod.POST)
    public ResponseEntity<List<UserVo>> getUserList(@RequestBody UserVo vo){

        return userManageService.getUserList(vo);

    }

    @ApiOperation("获取用户书架")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/getBookshelf" , method = RequestMethod.GET)
    public ResponseEntity<List<BookManageVo>> getBookshelf(int id,int pageNum){
        return userManageService.getBookshelf(id,pageNum);
    }

    @ApiOperation("查询用户借阅记录")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/getUserBorrow" , method = RequestMethod.GET)
    public ResponseEntity<List<BorrowVo>> getUserBorrow(int id,int pageNum){

        return userManageService.getUserBorrow(id,pageNum);

    }

    @ApiOperation("修改用户账号状态 0-》未冻结 1-》已冻结")
    @ApiResponses({
            @ApiResponse(code=0, message="成功"),
            @ApiResponse(code=500, message="系统异常"),
            @ApiResponse(code=999, message="未登录"),
            @ApiResponse(code=1000, message="数据有效性检查不通过"),
            @ApiResponse(code=1001, message="业务规则检查不通过")
    })
    @RequestMapping(value = "/updateUserState" , method = RequestMethod.GET)
    public ResponseEntity<List<UserVo>> updateUserState(int id,int state){

        return userManageService.updateUserState(id,state);

    }

}
